package com.example.demo.service.Impl;

import com.example.demo.common.domain.*;
import com.example.demo.mapper.DivisionManagerMapper;
import com.example.demo.service.EmployeeService;
import com.example.demo.service.LeaveService;
import com.example.demo.service.ManagerService;
import com.example.demo.service.MangerAble;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service("divisionService")
public class DivisionManagerServiceImpl extends ManagerService {

    @Autowired
    private DivisionManagerMapper divisionManagerMapper;
    @Autowired
    private LeaveService leaveService;

    private static DivisionManager divisionManager = null;
    
    @Override
    public void agreeLeaveItem(Integer lid) {
        assert lid != null;
        leaveService.updateDivIdByPrimaryId(lid,divisionManager.getDivid());
    }

    @Override
    public Manager getMangerInstance() throws Exception {
        if(divisionManager == null){
            List<DivisionManager> divisionManagers = divisionManagerMapper.selectByExample(null);
            if(divisionManagers.size() > 0){
                divisionManager =  divisionManagers.get(0);
                return divisionManager;
            }else{
                throw new Exception("从数据库里面找不到东西");
            }
        }
        return divisionManager;
    }
}
